package com.javasm.mb_store_api_final.sys_control.rolecontrol.sys_role.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javasm.mb_store_api_final.sys_control.rolecontrol.sys_role.dao.SysRoleDao;
import com.javasm.mb_store_api_final.sys_control.rolecontrol.sys_role.entity.SysRole;
import com.javasm.mb_store_api_final.sys_control.rolecontrol.sys_role.service.SysRoleService;
import com.javasm.mb_store_api_final.sys_control.usercontrol.sys_user.entity.SysUser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * (SysRole)表服务实现类
 *
 * @author makejava
 * @since 2024-07-29 20:18:46
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleDao, SysRole> implements SysRoleService {
    @Resource
    private SysRoleDao sysRoleDao;
    @Override
    public List<SysRole> selectAllRole() {
        List<SysRole> sysRoles = sysRoleDao.selectAllRole();
        Set<SysRole> sysRoleSet = new LinkedHashSet<>(sysRoles);
        return new ArrayList<>(sysRoleSet);
    }

    @Override
    public List<SysRole> queryBy(SysRole role) {
        List<SysRole> roles = sysRoleDao.queryBy(role);
        return roles;
    }

    @Override
    public long countall() {
        Long count = sysRoleDao.selectAllCount();
        return count;
    }

    @Override
    public void addRole(SysRole role) {
        sysRoleDao.addRole(role);
    }

    @Override
    public void updateRole(Integer roleId, SysRole role) {
        sysRoleDao.updateRole(roleId,role);
    }

    @Override
    public void deleteByRId(Integer roleId) {
        sysRoleDao.deleteByRId(roleId);
    }
    @Override
    public Map<String, Set<String>> paramList() {
        // 1. 查询所有用户
        List<SysRole> roles = sysRoleDao.selectAllRole();

        // 使用流处理来分别提取所需属性到对应的集合中
        Map<String, Set<String>> attributes = new HashMap<>();

        attributes.put("departName", roles.stream().map(SysRole::getDepartName).collect(Collectors.toSet()));
        attributes.put("roleState", roles.stream().map(role -> String.valueOf(role.getRoleState())).collect(Collectors.toSet()));
        attributes.put("posName", roles.stream().map(SysRole::getPosName).collect(Collectors.toSet()));
        attributes.put("roleName", roles.stream().map(SysRole::getRoleName).collect(Collectors.toSet()));
        // 返回Map对象
        return attributes;
    }
}
